<template>
  <button class="moly-button" :class="typeClass(type)">
    <span><slot></slot></span>
  </button>
</template>

<script>
export default {
  name: "MolyButton",
  props: {
    type: {
      type: String,
      default: "default",
    },
  },
  methods: {
    typeClass(type) {
      if (
        ["primary", "success", "info", "warning", "danger"].indexOf(type) != -1
      ) {
        return `moly-button--${type}`;
      } else {
        return `moly-button--default`;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.moly-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1;
  font-weight: 500;
  //禁止元素的文字被选中
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
  &:focus,
  &:hover {
    color: #409edd;
    border-color: #c6e2ff;
    background-color: #ecf5ff;
  }
}
.moly-button--primary {
  color: #fff;
  background: #409eff;
  border-color: #409eff;
  &:focus,
  &:hover {
    background: #66b1ff;
    border-color: #66b1ff;
    color: #fff;
  }
}
.moly-button--default {
  color: #409eff;
  background: #fff;
  border-color: #dcdfe6;
  &:focus,
  &:hover {
    background: #ecf5ff;
    border-color: #c6e2ff;
    color: #409eff;
  }
}
.moly-button--info {
  color: #fff;
  background: #909399;
  border-color: #909399;
  &:focus,
  &:hover {
    background: #a6a9ad;
    border-color: #a6a9ad;
    color: #fff;
  }
}
.moly-button--danger {
  color: #fff;
  background: #f56c6c;
  border-color: #f56c6c;
  &:focus,
  &:hover {
    background: #f78989;
    border-color: #f78989;
    color: #fff;
  }
}
.moly-button--warning {
  color: #fff;
  background: #e6a23c;
  border-color: #e6a23c;
  &:focus,
  &:hover {
    background: #ebb563;
    border-color: #ebb563;
    color: #fff;
  }
}
.moly-button--success {
  color: #fff;
  background: #67c23a;
  border-color: #67c23a;
  &:focus,
  &:hover {
    background: #85ce61;
    border-color: #85ce61;
    color: #fff;
  }
}
</style>